package books;

import java.util.ArrayList;
import java.util.List;

import users.Person;
import util.Entity;
import builders.BookRequestsInfoBuilder;

/**
 * Helper class for the reservation issue
 */
public class BookRequestsInfo extends Entity {

    private static final long serialVersionUID = 1L;

    private BookInfo book;

    private BookReservation reservedTo;

    private List<Person> notificationList;

    public BookRequestsInfo() {
        super();
        this.notificationList = new ArrayList<Person>();
    }

    public BookRequestsInfo(final BookInfo aBookInfo) {
        super();
        this.notificationList = new ArrayList<Person>();
        this.book = aBookInfo;
    }

    public BookRequestsInfo(final BookRequestsInfoBuilder builder) {
        super();
        this.book = builder.getBook();
        this.notificationList = builder.getNotificationList();
        this.reservedTo = builder.getReservedTo();
    }

    public void setReservedTo(final BookReservation reservedTo) {
        this.reservedTo = reservedTo;
    }

    public BookReservation getReservedTo() {
        return this.reservedTo;
    }

    public void setNotificationList(final List<Person> notificationList) {
        this.notificationList = notificationList;
    }

    public List<Person> getNotificationList() {
        return this.notificationList;
    }

    public boolean isReserved() {
        return this.reservedTo != null;
    }

    public void reserveTo(final BookReservation aReservation) {
        this.setReservedTo(aReservation);
    }

    public void clearReservation() {
        this.setReservedTo(null);
    }

    public void addPersonToNotificationList(final Person aPerson) {
        this.getNotificationList().add(aPerson);
    }

    public void clearNotificationList() {
        this.getNotificationList().clear();
    }

    public void copyReturned() {
        this.getReservedTo().copyReturned();
    }

    public void setBook(final BookInfo book) {
        this.book = book;
    }

    public BookInfo getBook() {
        return this.book;
    }

    public Book getReservedCopy() {
        // tirar exception si no esta reservado
        return this.getReservedTo().getReservedCopy();
    }

    public void reserveCopy(final Book aCopy) {
        this.getReservedTo().reserveCopy(aCopy);
    }

}
